# example5_4.py
import numpy as np
import os

current_dir = os.path.dirname(os.path.abspath(__file__))
csv_path = os.path.join(current_dir, "multi_stock.csv")

c, d, m = np.loadtxt(
    csv_path, delimiter=",", usecols=(1, 2, 3), unpack=True, skiprows=1
)
covCDM = np.cov([c, d, m])
relCDM = np.corrcoef([c, d, m])
print("C,D,M三家公司股票收盘价的协方差为：")
print(covCDM)
print("C,D,M三家公司股票收盘价的相关系数为：")
print(relCDM)
